import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/zh-cn'
dayjs.locale('zh-cn') // use locale
dayjs.extend(relativeTime);



export function currentRelativeTime(_id: string) {
    let timestamp = _id.toString().substring(0, 8)
    let date = new Date(parseInt(timestamp, 16) * 1000)
    if (!date) return ''
    return dayjs(date).fromNow()
}

export function transformationGoTime(time: string) {
    return time.substring(0, 19).replace('T', ' ')
}

export function ms(time: number) {
    return time < 60 ? `${time}秒` : `${Math.floor(time / 60)}分${time % 60}秒`
} 

export function YMDHMS(str?:any){
    return dayjs(str).format('YYYY-MM-DD HH:mm:ss');
}

